
(function($){
    var jjmask = function(obj, opt){
    	if(opt){
    		var jjmask = $('<div data="data-mask" style="overflow: hidden;background-color: #fff;opacity: 0.5;position: fixed;top: 0px;left: 0px;bottom: 0px;right: 0px;z-index: 999;"><i class="icon-spinner icon-spin icon-2x" style="top:50%;left:50%;position: absolute;color: #fff;font-size: 30px;"></i></div>');
    		$(obj).prepend(jjmask);
    	} else {
    		$(obj).find("[data='data-mask']").remove();
    	}
    	
	}
var options = {
};
$.fn.extend({
	jjmask:function(opt){
    	this.each(function(){
    		jjmask(this, opt);
        });
    }
});
})(jQuery);


(function($){
    var umeditorAdd = function(obj){
    	var oldId = $(obj).attr("id");
    	var id = "src"+oldId+new Date().getTime();
    	var width = $(obj).width();
    	var height = $(obj).height();
    	$(obj).hide();
    	var scr = $('<script type="text/plain" id="'+id+'" style="width:100%;height:'+height+'px;"></script>');
    	scr.insertAfter($(obj));
    	var um = UE.getEditor(id, {initialFrameHeight:400,initialFrameWidth:550,scaleEnabled:true});
    	$("#"+id).css("height","400px");
    	$("#"+id).css("display","inline-block");
    	
        um.addListener('blur',function(){
        	var con = $("<div></div>");
        	con.html(um.getContent());
        	con.find("img").css("max-width", "100%");
        	con.find("p").css("margin", "0px");
        	con.find("img").css("vertical-align", "bottom");
        	$(obj).val(con.html());
        });
        um.addListener('blur',function(){
        	//alert('');
        });
        um.ready(function() {//编辑器初始化完成再赋值  
        	um.setContent($(obj).val());
        });  
    }
    var umeditorUpd = function(obj, opt){
    	var oldId = $(obj).attr("id");
    	var id = "src"+oldId;
    	if(html != null && html != ''){
    		$("#"+id).val(html);
    	}
    	var um = UE.getEditor(id);
    	um.ready(function() {//编辑器初始化完成再赋值  
        	um.setContent($("#"+oldId).val());
        });
    }
    var umeditor = function(obj, opt){
    	if(opt != null){
    		$(obj).val(opt);
    	}
    	umeditorAdd(obj);
    }
    var options= {
    	url:""
    }
    $.fn.extend({
    	umeditor:function(opt){
        	this.each(function(){
        		umeditor(this, opt);
            });
        }
    });
})(jQuery);

(function($){
    var echartsLine = function(obj, opt){
    	var id = $(obj).attr("id");
    	var xAxisData = opt.xData;
    	var series = opt.yData;
    	option = {
		    tooltip : {trigger: 'axis'},
		    grid :{ borderWidth :'0px',y:"20px"},//去掉外边框
		    legend: {y:'bottom',data:[],selected: {}},
		    xAxis : [{type : 'category',splitLine :{show:false},boundaryGap : false,data : xAxisData}],
		    yAxis : [{show : true,//去掉Y轴
		    	type : 'value',
		    	splitLine :{show:true},//去掉竖线
	    		axisLine: {
		    		show: false,
		    		lineStyle: {
			    		color: '#e8e8e8',
			    		width: 1,
			    		type: 'solid'
		    			}
	    		}
		    }],
		    series : []
		};
		var index=0;
		$.each(series, function(i,v){
			if(v != null) {
				if(v.show){
					option.legend.selected[v.name] = true;
				} else {
					option.legend.selected[v.name] = false;
				}
				option.legend.data[index] = v.name;
				option.series[index] = {name:v.name,type:'line',data:v.data,markPoint : {
	                data : [
//    		                    {type : 'max', name: '最大值'},
//    		                    {type : 'min', name: '最小值'}
		                ]
		            },
		            markLine : {
		                data : [
//    		                    {type : 'average', name: '平均值'}
		                ]
		            }};
				index++;
			}
		});
		
		echarts.init(obj).setOption(option);
    }
    var options= {
    }
    $.fn.extend({
    	echartsLine:function(opt){
        	this.each(function(){
        		echartsLine(this, opt);
            });
        }
    });
})(jQuery);

//加载列表
(function($){
    var cleanList = function(obj){
    	$(obj).hide();
    	do{
    		if($(obj).prev() == null) {
    			return;
    		} else {
    			var data = $(obj).prev().attr("data");
        		if(data != 'loadList'){
        			return;
        		} else {
        			$(obj).prev().remove();
        		}
    		}
    	}while(true);
    }
    var loadData = function(obj, opt){
    	var htmltemp = $(obj).html();
    	htmltemp = $.loadData({html:htmltemp,data:opt});
    	var htmlobj = $(htmltemp);
    	htmlobj.attr("data","loadList");
    	$(obj).clean();
    	$(obj).before(htmlobj);
    }
    var options= {
    }
    $.fn.extend({
        clean:function(opt){
            this.each(function(){
            	cleanList(this, opt);
            });
        },
        loadData:function(opt){
        	this.each(function(){
        		loadData(this, opt);
            });
        }
    });
})(jQuery);



(function($){
	var pageSub = function(obj, opt){
		$("body").jjmask(true);
		var page = '<div class="table-page">'+
				'<div class="pagination-goto" style="float:left;">'+
			        '<button class="all-btn">显示全部</button>'+
			    '</div>'+
			
				'<div class="pagination-goto">'+
		            '<input type="text" class="goto-text" value="#{page}#"/> '+
		            '<button class="goto-btn">GO</button>'+
		        '</div>'+
		        '<ul class="pagination">'+
		            '<li class="page-left" data="1">‹‹</li>'+
		            '<li class="page-left" data="#{prev}#">‹</li>'+
		            '<li class="active disabled">#{page}#</li>'+
		            '<li class="page-right" data="#{next}#">›</li>'+
		            '<li class="page-right" data="#{totalPages}#">››</li>'+
		        '</ul>'+
		        '<div class="pagination-info">'+
	            	'共有#{totalElements}#条， 每页显示：<input type="text" class="page-size" value="#{size}#"/> 条'+
	            '</div>'+
		    '</div>';
		var ts = page.match(/#\{(\S*)(?=\}#)/g);
		
		$.ajax({url:opt.url,type:"get",cache:false,data:opt.data,success:function(data){
			data.obj.page = data.obj.number+1;
			data.obj.prev=data.obj.page-1;
			data.obj.next=data.obj.page+1;
			if(data.obj.page<=1){
				data.obj.prev = 1;
			}
			if(data.obj.page>=data.obj.totalPages){
				data.obj.next = data.obj.totalPages;
			}
			if(data.obj.totalElements <= 0){
				page = '<div class="table-page-null">未找到信息</div>'+page;
			}
			$.each(ts, function(i,v){
				var key = v.replace("#{","");
				var val = data.obj[key];
				page = page.replace(new RegExp(v+"}#","gm"), (val==null?"":val));
			});
			var pageobj = $(page);
			
			$.each(opt.customBtn, function(k,call){
        		var btn = $('<button class="cust-btn">'+k+'</button>')
        		btn.click(function(){
        			call();
        		});
        		pageobj.find(".all-btn").before(btn);
        	});
			
			if(data.obj.page<=1){
				pageobj.find(".pagination .page-left").addClass("disabled");
			}
			if(data.obj.page>=data.obj.totalPages){
				pageobj.find(".pagination .page-right").addClass("disabled");
			}
			pageobj.find(".pagination li").not(".disabled").click(function(){
	    		var data = $(this).attr("data");
	    		opt.data.page=(data-1);
	    		pageSub(obj, opt);
	    	});
			 pageobj.find(".goto-text").click(function(){
				 $(this).select();
			 });
			pageobj.find(".goto-text").change(function(){
				if(isNaN($(this).val())){
					$(this).val(data.obj.page);
				}
			});
			pageobj.find(".page-size").change(function(){
				if(isNaN($(this).val())){
					$(this).val(data.obj.size);
				} else {
					opt.data.size=$(this).val();
					pageobj.find(".goto-btn").click();
				}
			});
			
			pageobj.find(".goto-btn").click(function(){
				var val = pageobj.find(".goto-text").val();
				if(parseInt(val)>data.obj.totalPages){
					val = data.obj.totalPages;
				}
				opt.data.page=(val-1);
				pageSub(obj, opt);
			});
			pageobj.find(".all-btn").hide();
			var pageId = $(obj).attr("id");
			$.each(options.opt[pageId].data, function(i,v){
	    		if(i != "page" && i != "size" && v != '' && v != options.optInit[pageId].data[i]){
	    			pageobj.find(".all-btn").show();
	    		}
	    	});
			pageobj.find(".all-btn").click(function(){
				pageCleanReLoad(obj, null);
			});
			
			//后面加#跟参数
			if(opt.urlUpdate){
				var url = "#";
				$.each(opt.data, function(k,v){
					if(v != null){
						url+="&"+k+"="+v;	
					}
				});
				location.href=url;
			}
			updateMenuUrl();
			
			$(obj).html(pageobj);
			$("body").jjmask(false);
			opt.success(data);
		}});
	}
	
	var pageInit = function(obj, opt){
    	var pageId = $(obj).attr("id");
    	options.optInit[pageId]= $.extend({}, opt, {});
    	
    	if(opt.urlUpdate){
    		var params = decodeURI(location.href).split("#");
    		var paramData = {};
    		if(params.length>1) {
    			var param = params[1].split("&")
    			for(var i=0;i<param.length;i++) {
    				var v = param[i];
    				if(v != null && v != '') {
    					var value = v.split("=");
    					if(value.length >1 && value[1] != '') {
    						paramData[value[0]]=value[1];	
    					}
    				}
    			}
    		}
    		opt.data = $.extend({}, opt.data, paramData||{});
    	}
    	var pageobj = page(obj, opt);
    }
	
    var page = function(obj, opt){
    	var pageId = $(obj).attr("id");
    	if(opt.data.page == null) {
    		opt.data.page = 0;
    	}
    	options.opt[pageId]=opt;
    	var pageobj = pageSub(obj, opt);
    }
    var pageReLoad = function(obj, data){
    	var pageId = $(obj).attr("id");
    	if(data != null){
	    	$.each(data, function(i,v){
	    		if(i != "page" && options.opt[pageId].data[i] != data[i]){
	    			data.page=0;
	    			return;
	    		}
	    	});
    	}
    	options.opt[pageId].data = $.extend({}, options.opt[pageId].data, data||{});
    	page(obj, options.opt[pageId]);
    }
    var pageCleanReLoad = function(obj, data){
    	var pageId = $(obj).attr("id");
    	options.opt[pageId].data = $.extend({}, options.optInit[pageId].data, data||{});
    	page(obj, options.opt[pageId]);
    }
    var options= {
    	data:{size:10,page:0},
    	url:"",
    	type:"get",
    	customBtn:{},
    	customSuccess:function(){},
    	opt:{},
    	optInit:{},
    	urlUpdate:true,
    	success:function(obj){
    		
    	}
    }
    $.fn.extend({
        page:function(opt){
        	var opt2 = $.extend({}, options, opt||{});
            this.each(function(){
            	pageInit(this, opt2);
            });
        },
        pageReload:function(data){
            this.each(function(){
            	pageReLoad(this, data);
            });
        },
        pageCleanReload:function(data){
            this.each(function(){
            	pageCleanReLoad(this, data);
            });
        },
        getPageData:function(){
        	return options.opt[$(this).attr("id")].data;
        }
    });
})(jQuery);



(function($){
    var repModal=function(opt, infoHtml){
        var modalHtml = '<div data="modal_#{id}">#{infoHtml}</div>';
        modalHtml = modalHtml.replace("#{infoHtml}",infoHtml).replace("#{id}",opt.id).replace("#{id}",opt.id);
        var modal = $(modalHtml);
        
        if(options.modalPage.length == 0){
        	alert("请先addPath");
        	return;
        }
        $("#"+options.modalPage[0].id).hide();
        $("#"+options.modalPage[0].id).after(modal);
        opt.succ(modal);
    }
    
    var setData=function(obj, data){
    	var infoHtml = $(obj).html();
    	var id = $(obj).attr("id");
    	options.oldData[id] = $.extend({}, options.oldData[id], data||{});
    	infoHtml = $.loadData({html:infoHtml,data:options.oldData[id]});
    	var no = $("<div></div>");
    	$("div[data=modal_"+id+"]").find("[data='modal-static']").each(function(i,v){
    		$(v).appendTo(no);
    	});
    	$("div[data=modal_"+id+"]").html(infoHtml);
    	var newModal = $("div[data=modal_"+id+"]").find("[data='modal-static']");
    	no.find("[data='modal-static']").each(function(i,v){
    		var stName = $(v).attr("data");
    		var st = newModal.get(i);
    		//var st = $("div[data=modal_"+id+"]").find("div[data='"+stName+"']");
    		$(st).before($(v));
    		$(st).remove();
    	});
    	
    	$.each(options.oldSaveFun[id], function(i,fun){
        	fun(options.oldData[id]);
        });
    }
    
    var getData = function(obj, key, value){
    	if(key == null || key == ''){
    		return options.oldData[id];
    	} else {
    		if(options.oldData[id] != null && options.oldData[id][key] != null){
    			
    			return options.oldData[id][key];
    		} else if(value != null){
    			options.oldData[id][key] = value;
    			return options.oldData[id][key];
    		} else {
    			return "";
    		}
    	}
    	
    }
    
    var setMain=function(obj, fun){
    	var id = $(obj).attr("id");
    	if(options.oldSaveFun[id] == null){
        	options.oldSaveFun[id]=[];
        }
    	options.oldSaveFun[id].push(fun);
    }
    
    var modal = function(obj, opt){
        var infoHtml = $(obj).html();
        opt.id = $(obj).attr("id");
        $("div[data=modal_"+opt.id+"]").remove();
        
        $("div[data*=modal_]").hide();
        options.oldData[opt.id] = {};
        repModal(opt, infoHtml);
        if(opt.oldId != null){
            
        }
        setData(obj);
        
    }
    var addPath = function(obj, opt){
    	id = $(obj).attr("id");
    	var index=-1;
    	$.each(options.modalPage, function(i,v){
    		if(v.id==id){
    			$(obj).attr("data", "modal_"+id);
    			v.name=opt;
    			index = i;
    		}
    	});
    	if(index == -1){
    		$(obj).attr("data", "modal_"+id);
    		options.modalPage.push({id:id, name:opt});
    	}
    	loadModalPage(options.modalPage);
    	return options.modalPage;
    }
    
    var loadModalPage = function(modalPage){
    	var mp = [];
    	$.each(modalPage, function(i,v){
    		if(v.name != null && v.name != ''){
    			mp.push(v);
    		}
    	});
    	$("#navList").loadData({navList:mp});
    }
    
    var callmodal = function(obj){
    	var id=$(obj).attr("id");
    	if(options.opt[id] != null){
    		$("div[data=modal_"+id+"]").remove();
    		$("#"+options.opt[id]).show();
    	} else {
    		$("div[data=modal_"+id+"]").remove();
    	}
    }
    var showPage = function(obj){
    	var id=$(obj).attr("id");
    	$("div[data*=modal_]").hide();
    	$("div[data='modal_"+id+"']").show();
    	var index=-1;
    	$.each(options.modalPage, function(i,v){
    		if(v.id==id){
    			index = i;
    		}
    	});
    	options.modalPage.splice(index+1,options.modalPage.length);
    	loadModalPage(options.modalPage);
    }
    var options = {
    	modalPage:[],
        oldId:null,
    	succ:function(){},
        data:{},
        oldSaveFun:{},
        oldData:{}//保存的数据
    };
    $.fn.extend({
        showmodal:function(opt){
            var opt2 = $.extend({}, options, opt||{});
            this.each(function(){
                modal(this, opt2);
            });
        },
        callmodal:function(){
            this.each(function(){
            	callmodal(this);
            });
        },
        setData:function(opt){
            this.each(function(){
            	setData(this, opt);
            });
        },
        setMain:function(opt){
            this.each(function(){
            	setMain(this, opt);
            });
        },
        addPath:function(opt){
            return addPath(this, opt);
        },
        showPage:function(){
	    	 this.each(function(){
	    		 showPage(this);
	         });
        },
        getData:function(key, value){
        	return getData(this, key, value);
        }
    });

})(jQuery);



/*自定义标签*/
(function($){
	var replaceHtml = function(html, data){
		var ts = html.match(/#\{(\S*)(?=\}#)/g);
        if(ts != null){
        	$.each(ts, function(i,v){
            	var k = v.replace("#{","");
            	var value = hsHanldGet(data, k);
            	html = html.replace(v+"}#",value);
            });
        }
        return html;
	}
	
	var hsHanldGet=function(data, key){
		if(data == null){
			return "";
		}
		var k1 = '';
		var bIndex = key.indexOf(".");
		if(bIndex == -1){
			k1 = key;
		} else {
			k1 = key.substring(0, bIndex);
			var k2 = key.substring(bIndex+1, key.length);
			return hsHanldGet(data[k1], k2);
		}
		return (data[k1]==null?"":data[k1]);
	}
	
	var searData = function(data, all, key){
		var d;
		var bIndex = key.indexOf(".");
		var k1;
		if(bIndex != -1){
			k1 = key.substring(0, bIndex);
		} else {
			k1 = key;
		}
		if(data[k1] != null){
			d = data;
		} else if(all != null && all[k1] != null){
			d = all;
		}
		return d;
	}
	
	var hsHanld = function(value, bm, data, all){
		var hxs = [">=", "<=", "!=", "==", "<", ">"];
		var flag = false;
		$.each(hxs, function(i,hs){
			if(value.indexOf(hs)!= -1){
				var k = value.split(hs)[0];
				if(bm != null && bm != ''){
	    			k = k.replace(bm+".", "");
				}
				var v = value.split(hs)[1];
				
				if(v.substring(0,1) == "'" && v.substring(v.length-1, v.length) == "'"){
					val2 = v.substring(1, v.length-1);
				} else {
					if(bm != null && bm != ''){
		    			v = v.replace(bm+".", "");
					}
					var d2 = searData(data, all ,v);
					val2 = hsHanldGet(d2, v);
				}
				
				var d = searData(data, all ,k);
				var val1 = hsHanldGet(d, k);
				
				
				if((hs == '>=' && val1 >= val2) || (hs == '<=' && val1 <= val2) 
						|| (hs == '!=' && val1 != val2) || (hs == '=' && val1 == val2) 
						|| (hs == '==' && val1 == val2) || (hs == '>' && val1 > val2) || (hs == '<' && val1 < val2)){
					flag = true;
				}
				return 2;
			} else {
				if(bm != null && bm != ''){
	    			var k = value.replace(bm+".", "");
	    			var flag2 = true;
	    			if(k.indexOf("!") == 0){
	    				flag2 = false;
	    				k = k.replace("!", "");
	    			}
	    			var d = searData(data, all ,k);
	    			var val1 = hsHanldGet(d, k);
	    			if(val1 && flag2){
	    				flag= true;
	    			} else if(val1==false && flag2==false){
	    				flag= true;
	    			}
				}
			}
		});
		return flag;
	}
	
	var getIfSonHtml = function(html, bIndex, eIndex, i){
		var tempEnd = "#endif#";
		var tempHtml = html.substring(bIndex, eIndex);
		var iftemps = tempHtml.match(/#if\((\S*)(?=\)#)/g);
		if(iftemps != null){
			if(i == iftemps.length){
				return eIndex;
			}
			eIndex = html.indexOf(tempEnd, eIndex+tempEnd.length);
			i++;
			return getIfSonHtml(html, bIndex, eIndex, i);
		}
	}
	
	var replaceIf=function(tempHtml, data, bm, all){
		bm = (bm==null?'':bm)
    	var iftemps = tempHtml.match(/#if\((\S*)(?=\)#)/g);
    	if(iftemps != null){
	    	$.each(iftemps, function(i,tempv){
	    		var tempbegin = tempv+")#"
	        	var tempEnd = "#endif#";
	    		var value = tempv.replace("#if(", "");
	    		var bIndexOf = 0;
	    		while(bIndexOf != -1){
	    			var htmls = '';
	    			bIndexOf = tempHtml.indexOf(tempbegin, bIndexOf);
	    			if(bIndexOf != -1){
	    				var eIndexOf = tempHtml.indexOf(tempEnd, bIndexOf);
	    				eIndexOf = getIfSonHtml(tempHtml, bIndexOf, eIndexOf, 1);
	    				var html = tempHtml.substring(bIndexOf+tempbegin.length, eIndexOf);
	    				
	    				var flag = hsHanld(value, bm, data, all);
	    				if(flag){
	    					htmls = html+'';
	    				}
	    	    		tempHtml = tempHtml.substring(0, bIndexOf)+ htmls +tempHtml.substring(eIndexOf+tempEnd.length, tempHtml.length);
	    			}
	    			
	    		}
	    	});
    	}
    	return tempHtml;
	}
	
	var getForSonHtml = function(html, bIndex, eIndex, i){
		var tempEnd = "#endfor#";
		var tempHtml = html.substring(bIndex, eIndex);
		var iftemps = tempHtml.match(/#for\((\S*)(?=\)#)/g);
		if(iftemps != null){
			if(i == iftemps.length){
				return eIndex;
			}
			eIndex = html.indexOf(tempEnd, eIndex+tempEnd.length);
			i++;
			return getForSonHtml(html, bIndex, eIndex, i);
		}
	}
	
	var replaceFor=function(tempHtml, data, bm2, all){
		var temps = tempHtml.match(/#for\((\S*)(?=\)#)/g);
    	var newHtml = tempHtml+'';
    	if(temps != null){
    		newHtml = '';
	    	$.each(temps, function(i,v){
	    		var tempbegin = v+")#"
	        	var tempEnd = "#endfor#";
	    		var bIndexOf = 0;
	    		while(bIndexOf != -1){
	    			bIndexOf = tempHtml.indexOf(tempbegin, bIndexOf);
	    			if(bIndexOf != -1){
	    				
	    				var eIndexOf = tempHtml.indexOf(tempEnd, bIndexOf);
	    				eIndexOf = getForSonHtml(tempHtml, bIndexOf, eIndexOf, 1);
	    				var html = tempHtml.substring(bIndexOf+tempbegin.length, eIndexOf);
	    				var value = v.replace("#for(", "");
	    	    		var key = value.split(":")[1];
	    	    		if(bm2 != null && bm2 != ''){
	    	    			key = key.replace(bm2+".", "");
	    				}
	    	    		var bm = value.split(":")[0];
	    	    		
	    	    		
	    	    		var newHtml = '';
	    	    		if(data != null && data[key] != null && value.indexOf(".")!=-1){
	    	    			var ts = html.match(/#\{(\S*)(?=\}#)/g);
	    	    			$.each(data[key], function(i3,v3){
	    	    				var ht = html+"";
	    	    				all[bm]=v3;
	    	    				ht = replaceFor(ht, v3, bm, all);
	    		    			ht = replaceIf(ht, v3, bm ,all);
//	    		    			$.each(ts, function(i2,v2){
//	    		    				var k = v2.replace("#{", "");
//	    		        			if(k == bm){
//	    		        				var value = (v3==null?"":v3);
//	    		        				ht= ht.replace(v2+"}#", value);
//	    		        			} else {
//	    		        				k = k.replace(bm+".","");
//	    		        				var value = hsHanldGet(v3, k);
//	    		        				ht= ht.replace(v2+"}#", value);
//	    		        			}
//	    		        			
//	    		        		});
	    		    			ht = replaceHtml(ht, all);
	    		    			newHtml+=ht;
	    		    		});
	    	    		} else if(all != null && all[key] != null && value.indexOf(".")==-1){
	    	    			var ts = html.match(/#\{(\S*)(?=\}#)/g);
	    	    			$.each(all[key], function(i3,v3){
	    	    				var ht = html+"";
	    	    				all[bm]=v3;
	    	    				ht = replaceFor(ht, v3, bm, all);
	    		    			ht = replaceIf(ht, v3, bm ,all);
//	    		    			$.each(ts, function(i2,v2){
//	    		    				var k = v2.replace("#{", "");
//	    		        			if(k == bm){
//	    		        				ht= (v3==null?"":v3);
//	    		        			} else {
//	    		        				k = k.replace(bm+".","");
//	    		        				var value = hsHanldGet(v3, k);
//	    		        				ht= ht.replace(v2+"}#", value);
//	    		        			}
//	    		        		});
	    		    			ht = replaceHtml(ht, all);
	    		    			newHtml+=ht;
	    		    		});
	    	    		}
	    	    		tempHtml = tempHtml.substring(0, bIndexOf)+ newHtml +tempHtml.substring(eIndexOf+tempEnd.length, tempHtml.length-1);
	    			}
	    		}
	    	});
	    	newHtml = newHtml+tempHtml;
    	}
    	return newHtml;
	}
	
    var main = function(opt){
    	var newHtml = opt.html;
    	newHtml = replaceFor(newHtml, opt.data, '', opt.data);
    	
    	newHtml = replaceIf(newHtml, opt.data);
    	
    	if(newHtml == ''){
    		newHtml = opt.html;
    	}
    	newHtml = replaceHtml(newHtml, opt.data);
    	return newHtml;
    }
    var options = {
        html:"",
        data : {}
    };

    $.extend({
        loadData:function(opt) {
            var opt2 = $.extend({}, options, opt||{});
            return main(opt2);
        }
    });
})(jQuery);

(function($){
	var ajaxData = function(obj, opt){
    	var data;
    	var async = false;
    	if(opt.success != null) {
    		async = true;
    	}
    	if(opt.isMask){
    		$("body").jjmask(true);	
    	}
    	$.ajax({async:async, url:opt.url,type:opt.type,dataType:"json",cache:false,data:opt.data, success:function(obj){
    		$("body").jjmask(false);
    		data = obj.obj;
    		if(obj.success){
    			if(opt.success != null){
        			opt.success(data);
        		}
    		} else {
    			if(obj.code == '0001') {
					$.jjalert({text:obj.msg,yes:function(){
						location.reload();
					}});
					return;
				} else {	
					$.jjalert({title:"警告",text:obj.msg});
				}
    			
    		}
    	},error:function(obj){
    		$("body").jjmask(false);
    		$.jjalert({title:"错误",text:"系统繁忙"});
    	}});
    	return data;
    }
    var options = {
    	isMask:true,
    	url:"",
    	type:"get",
    	success:null,
    	data:{}
    };
    $.extend({
    	ajaxData:function(opt) {
    		var opt2 = $.extend({}, options, opt||{});
        	return ajaxData(this, opt2);
        }
    });
})(jQuery);



//打开流媒体
(function($){
	var openVideo = function(opt){
		  
		var id = "player_"+new Date().getTime();
		var html = '<div style="text-align: center;position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;z-index: 999;padding: 50px 0px;">'+
			'<div style="display: inline-block;padding: 50px 100px;background: #000;width:800px;height:500px;"><video id="'+id+'" class="video-js mobile-first-skin" controls preload="auto" style="display: inline-block;"></div>'+
			'<span data="close" style="padding: 5px 15px;display: inline-block;background: #383838;color: #fff;cursor: pointer;font-size: 20px;position: absolute;">×</span></div>'+
			'</div>';
		var htmlObj = $(html);
		htmlObj.find("span[data='close']").click(function(){
			htmlObj.remove();
			player.dispose();
			opt.close();
		});
		$("body").append(htmlObj);
		
		var player = ksplayer(id,{
	        language: 'zh-CN',
	        bigPlayButton: true,
	        autoplay:false,
	        controlBar: {
	            volumeMenuButton: {
	                inline: false,
	                vertical: true
	            }  
	        }
	    });
		htmlObj.find(".vjs-menu").hide();
		htmlObj.find(".vjs-volume-menu-button").on({  
          mouseover : function(){  
          	htmlObj.find(".vjs-menu").show();
          },
          mouseout : function(){
          	htmlObj.find(".vjs-menu").hide();
          }   
      })
		htmlObj.find(".video-js").css("width","100%");
		htmlObj.find(".video-js").css("height","100%");
      
	    player.ready(function() {
	    	var newUrl = opt.url;
	        if(newUrl.indexOf('rtmp') == 0) {
	            if(window.hasFlash) {
	                player.src({"type":"rtmp/flv", "src":newUrl });
	                player.play();
	            }else {
	                alert('您的浏览器没有安装flash插件或flash被禁用');
	            }
	        }else if(newUrl.indexOf('http') == 0 && newUrl.endWith('.mp4')) {
	            player.src({"type":"video/mp4", "src":newUrl });
	            player.play();
	        }else if(newUrl.indexOf('http') == 0 && newUrl.endWith('.m3u8'))  {
	            player.src({"type":"application/x-mpegURL", "src":newUrl });
	            player.play();
	        }else if(newUrl.indexOf('http') == 0 && newUrl.indexOf('.flv') != -1) {
	            if(window.hasFlash) {
	                player.src({"type": "video/x-flv", "src": newUrl});
	                player.play();
	            }else {
	                alert('您的浏览器没有安装flash插件或flash被禁用');
	            }
	        }
	    });
		
	}
  var options = {
  		fileName:"",
  		rtmpUrl:"",
  		error:function(){},
  		close:function(){}
  };
  $.extend({
  	openVideo:function(opt) {
  		var opt2 = $.extend({}, options, opt||{});
      	return openVideo(opt2);
      }
  });
})(jQuery);




(function($){
	
	var selectImg;
    var uploadYd = function(upload, img){
    	var isDialogTitle=false;
    	img.on({
    		mousedown: function(e){
    			e.preventDefault();
	            var el=$(this).parent().parent();
	            el.attr("style", 'z-index: 2;');
	            var os = el.offset(); dx = e.pageX-os.left, dy = e.pageY-os.top;
	            $(document).on('mousemove.drag', function(e2){ 
	            	upload.find(".opt-row").each(function(i,v){
	            		var height = $(v).height();
	            		var width = $(v).width();
	            		
	            		var offLeftStart = $(v).offset().left;
	            		var offLeft = offLeftStart+(width/2);
	            		var offLeftEnd = offLeftStart+width;
	            		
	            		var offTopStart = $(v).offset().top;
	            		var offTop = offTopStart+(height/2);
	            		var offTopEnd = offTopStart+height;
	            		if(e2.pageX >=offLeftStart &&  e2.pageX <=offLeftEnd){
	            			if(e2.pageY >= offTopStart && e2.pageY <= offTop){
		            			$(v).before(el)
		            		} else if(e2.pageY <= offTopEnd && e2.pageY >= offTop){
		            			$(v).after(el)
		            		}
	            		}
	            	});
	            	el.offset({top: e2.pageY-dy, left: e2.pageX-dx}); 
	            	isDialogTitle = true;
	            	selectImg = el;
	            });
    		},
    		mouseup: function(e){ 
    			var el=$(this).parent().parent();
    			el.attr("style", '');
    			$(document).off('mousemove.drag');
    			isDialogTitle = false;
    			selectImg = null;
    		}
    	});
    }
	
	var addTextOption = function(textObj, value){
		var html = '<div class="opt-text-option">'+
					'<input class="opt-text-option-txt" placeholder="选项" value="'+value+'" type="text"/>'+
					'</div>';
		var htmlObj = $(html);
		textObj.append(htmlObj);
		htmlObj.find(".opt-text-option-txt").change(function(){
			var value = $(this).val();
			if(value == '' && htmlObj.parent().prev().length > 0){
				$(this).parent().remove();
			} else if(value != '' && htmlObj.parent().next().length == 0){
				addTextOption(textObj, "");
			}
		});
	}
	
	var add = function(optObj, data){
		var html = '<div class="opt-row">'+
						'<div class="opt-top">'+
						'<div class="opt-select">'+
							'<div class="opt-type-text" data="0">文本</div>'+
							'<div class="opt-type">'+
								'<div class="opt-type-value" data="0">文本</div>'+
								'<div class="opt-type-value" data="1">单选</div>'+
								'<div class="opt-type-value" data="2">多选</div>'+
								'<div class="opt-type-value" data="3">图片</div>'+
								'<div class="opt-type-value" data="4">日期</div>'+
							'</div>'+
						'</div>'+
						'<div class="opt-name">'+
							'<input class="opt-name-txt" placeholder="名称" value="'+(data.name==null?"":data.name)+'" type="text"/>'+
						'</div>'+
						'<div class="opt-desc">'+
							'<input class="opt-desc-txt" placeholder="提示信息" value="'+(data.desc==null?"":data.desc)+'" type="text"/>'+
						'</div>'+
						'<div class="opt-isRequired">'+
							'必填'+
						'</div>'+
						'<div class="opt-td">'+
							'<i class="opt-td-icon"></i>'+
						'</div>'+
					'</div>'+
					'<div class="opt-text">'+
						
					'</div>'+
				'</div>';
		var htmlObj = $(html);
		optObj.append(htmlObj);
		htmlObj.find(".opt-name-txt").change(function(){
			var value = $(this).val();
			if(value == '' && htmlObj.prev().length > 0){
				htmlObj.remove();
			} else if(value != '' && htmlObj.next().length == 0){
				add(optObj, {name:"",type:"0",text:""});	
			}
		});
		
		htmlObj.find(".opt-type-value").click(function(){
			var typeName = $(this).html();
			var type = $(this).attr("data");
			htmlObj.find(".opt-type-text").html(typeName);
			htmlObj.find(".opt-type-text").attr("data", type);
			if(type == '1' || type == '2'){
				htmlObj.find(".opt-text").show();
			} else {
				htmlObj.find(".opt-text").hide();
			}
		});
		
		htmlObj.find(".opt-type-value[data='"+data.type+"']").click();
		
		if(data.text == null || data.text == ''){
			addTextOption(htmlObj.find(".opt-text"), "");
		} else {
			$.each(data.text.split(","), function(i,v){
				addTextOption(htmlObj.find(".opt-text"), v);
			});
			addTextOption(htmlObj.find(".opt-text"), "");
		}
		if(data.isRequired != null && data.isRequired){
			htmlObj.find(".opt-isRequired").addClass("active");
		}
		htmlObj.find(".opt-isRequired").click(function(){
			if($(this).hasClass("active")){
				$(this).removeClass("active");
			} else {
				$(this).addClass("active");
			}
			
		});
		uploadYd(optObj, htmlObj.find(".opt-td"));
	}
	
	var openOption = function(opt){
		var html = '<div class="opt"><div class="opt-body"></div><div class="opt-foot"><button class="opt-save">保存</button></div><div/>';
		var htmlObj = $(html);
		var jjalert = $.jjalert({title:"栏目",text:htmlObj,hasBtn:false});
		
		htmlObj.find(".opt-save").click(function(){
			var data = [];
			htmlObj.find(".opt-row").each(function(){
				var type = $(this).find(".opt-type-text").attr("data");
				var name = $(this).find(".opt-name-txt").val();
				var desc = $(this).find(".opt-desc-txt").val();
				var isRequiredLength = $(this).find(".opt-isRequired.active").length;
				var isRequired = false;
				if(isRequiredLength>0){
					isRequired = true;
				}
				if(name != ''){
					var text = "";
					$(this).find(".opt-text-option-txt").each(function(i,v){
						if($(v).val() != ''){
							text += $(v).val()+",";
						}
					});
					if(text != ''){
						text = text.substring(0, text.length-1);
					}
					data.push({name:name,type:type,text:text,desc:desc,isRequired:isRequired});
				}
			});
			opt.save(data);
			jjalert.remove();
		});
		
		if(opt.data.length == 0){
			add(htmlObj.find(".opt-body"), {name:"",type:"0",text:""});
		} else {
			$.each(opt.data, function(i,v){
				add(htmlObj.find(".opt-body"), v);	
			});
			add(htmlObj.find(".opt-body"), {name:"",type:"0",text:""});
		}
		
	}
var options = {
	data:[],
	save:function(){}
};
$.extend({
	openOption:function(opt) {
		var opt2 = $.extend({}, options, opt||{});
    	return openOption(opt2);
    }
});
})(jQuery);




(function($){
	
	var getUser = function(opt){
		$.listAlertData({title:opt.title,url:"/v3/plugin/user",data:opt.data,cols:{"ID":"id","编号":"number","昵称":"name","类型":"typeDesc"},success:function(v){
  	  		opt.click(v);
  	  	}});
	}
	var options = {
		click:function(){}
	};
	$.extend({
		getUser:function(opt) {
			var opt2 = $.extend({}, options, opt||{});
	    	return getUser(opt2);
	    }
	});
})(jQuery);




(function($){
	var listAlertData = function(opt){
		var time = new Date().getTime();
		var html='<div class="desc">'+
		'<div class="list-sears">'+
	    	'<div class="list-sear-box">'+
	    		'<input class="list-sear-text" type="text" data="name" placeholder="请输入关键词" value=""/>'+
	    	'</div>'+
	    	'<div class="list-sear-box">'+
	    		'<input class="list-sear-text" type="text" data="date" readonly="readonly" onfocus="WdatePicker({dateFmt: \'yyyy-MM-dd\'})" placeholder="日期" value=""/>'+
	    	'</div>'+
	    	'<div class="list-sear-btn" onclick="pageParam(this, \'listPage'+time+'\')">搜索</div>'+
    	'</div>'+
		
		'<div class="desc-body">'+
	    '<div class="table_list">'+
              '<div class="table-overflow">'+
                  '<table class="table">'+
                      '<thead>'+
                          '<tr>'+
                          	'<th class="">选择</th>'+
                          	'#{ths}#'+
                          '</tr> '+
                      '</thead>'+
                      '<tbody  id="list'+time+'">'+
                    '</tbody>'+
                '</table>'+
            '</div>'+
			'<div id="listPage'+time+'"></div>'+
         '</div>'+
         '<div class="list-btn" style="text-align: center;">'+
      		'<button class="list-btn-item" id="listAlertDataCancel" onclick="">取消</button>'+
			'<button class="list-btn-item" id="listAlertDataSuccess" onclick="">保存</button>'+
		 '</div'+
 	'</div>'+
'</div>';
		var ths = "";
		$.each(opt.cols, function(k,v){
			ths+= '<th>'+k+'</th>';
		});
		html = $.loadData({data:{ths:ths},html:html})
		var htmlObj = $(html);
		htmlObj.find("#listAlertDataSuccess").click(function(){
			jjalert.remove();
			$("body").css({"overflow":"auto"});
			opt.success(opt.ids);
		});
		htmlObj.find("#listAlertDataCancel").click(function(){
			jjalert.remove();
			$("body").css({"overflow":"auto"});
		});
		if(opt.data.size == null){
			opt.data.size = 7;
		}
		var jjalert = $.jjalert({title:opt.title,text:htmlObj,hasBtn:false});
		$("#listPage"+time).page({url:opt.url,data:opt.data,urlUpdate:false, success:function(ret){
			var tr = ' <tr>';
			tr+= ' <td><input type="checkbox" value="#{id}#"/></td>';
			$.each(opt.cols, function(k,v){
				tr+= ' <td>'+v+'</td>';
			});
			tr += ' </tr>';
			$("#list"+time).html("");
  			$.each(ret.obj.content, function(i,v){
  				v.createdAt = new Date(v.createdAt).Format("yyyy-MM-dd HH:mm");
    			var trObj = $($.loadData({data:v,html:tr}));
    			if(opt.ids.indexOf(v.id) != -1){
    				trObj.find("input[type='checkbox']").prop("checked","checked");
    			}
    			trObj.find("input[type='checkbox']").change(function(){
    				if($(this).is(':checked') && opt.ids.indexOf(v.id) == -1){
    					opt.ids.push(v.id);
    				} else {
    					arryRemove(opt.ids, v.id);
    				}
    			});
    			$("#list"+time).append(trObj);
    		});
  		}});
	}
	
	var arryRemove = function(arry, val) {
		var index = arry.indexOf(val);
		if (index > -1) {
			arry.splice(index, 1);
		}
	};
	
	var options = {
		url:"",
		data:{},
		ids:[],
		cols:[],
		success:function(){}
	};
	$.extend({
		listAlertData:function(opt) {
			var opt2 = $.extend({}, options, opt||{});
	    	return listAlertData(opt2);
	    }
	});
})(jQuery);


(function($){
    var showDate=function(that, opt){
    	var date = new Date().getTime();
    	var html = '<div class="ta_date" style="border: 0px;border-radius: 0px;background: #fff;">'+
            '<span class="date_title" id="picker'+date+'">请选择日期</span>'+
            '<a class="opt_sel" href="javascript:void(0)">'+
                '<i class="i_orderd"></i>'+
            '</a>'+
		'</div>';
    	$(that).append(html);
    	
    	var dateRange = new pickerDateRange('picker'+date, {
            isTodayValid : true,
            startDate:opt.beginAt==null?'':opt.beginAt,
            endDate:opt.endAt==null?'':opt.endAt,
            defaultText : ' 至 ',
            theme : 'ta',
            success : function(obj) {
            	opt.success({beginAt:obj.startDate,endAt:obj.endDate});
            }
        });
    }
    var options = {
    	beginAt:null,
    	endAt:null,
    	success:function(){
    		
    	}
    };
    $.fn.extend({
        showDate:function(opt){
            var opt2 = $.extend({}, options, opt||{});
            this.each(function(){
            	showDate(this, opt2);
            });
        }
    });

})(jQuery);




(function($){
	
	var loadMedia = function(htmlObj, data){
		if(data.type=='PIC'){
			htmlObj.find("#mediaView").html('<img style="max-width: 900px;max-height: 600px;" alt="" src="'+data.url+'">');
		} else if(data.type=='VIDEO'){
			var newUrl = data.url.replace('.com/', ".com/m_");
			htmlObj.find("#mediaView").html('<video  controls="controls"  style="max-width: 900px;max-height: 600px;">'+
			'<source src="'+newUrl+'" type="video/mp4">'+
			'<source src="'+data.url+'" type="video/mp4">'+		
			'</video>');
			
		}
	}
	
	var loadPage = function(htmlObj, opt){
		htmlObj.find("#mediaCount").html(opt.page);
		htmlObj.find("#mediaTotal").html(opt.data.length);
	}
	
	
	var showMedia = function(opt){
		var htmlObj = $('<div style="position: fixed;display: flex;justify-content: center;left: 0px;right: 0px;top: 0px;bottom: 0px;align-items: center;background: #000;z-index: 999;">'+
		'<span id="mediaClose" style="position: absolute;right: 30px;top:30px;background: #ff5001;color:#fff;padding: 10px 20px;border-radius: 5px;cursor: pointer;">关闭</span>'+
   		'<span id="mediaPre" style="position: absolute;left: 30px;background: #ff5001;color:#fff;padding: 10px 20px;border-radius: 5px;cursor: pointer;">上一个</span>'+
   		'<div id="mediaView">'+
   		'</div>'+
   		'<span id="mediaNext" style="position: absolute;right: 30px;background: #ff5001;color:#fff;;padding: 10px 20px;border-radius: 5px;cursor: pointer;">下一个</span>'+
   		'<div style="position: absolute;bottom: 10px;padding: 10px 20px;background: #fff;opacity: 0.2;font-size: 14px;">'+
			'<span id="mediaCount">1</span>/<span id="mediaTotal">10</span>'+
		'</div>'+
    '</div>');
		htmlObj.find("#mediaClose").click(function(){
			htmlObj.remove();
		});
		
		if(opt.data.length > 0){
			loadMedia(htmlObj, opt.data[opt.page-1]);
		}
		
		htmlObj.find("#mediaNext").click(function(){
			if(opt.page<opt.data.length){
				opt.page++;
				loadPage(htmlObj, opt);
				loadMedia(htmlObj, opt.data[opt.page-1]);
			}
		});
		
		htmlObj.find("#mediaPre").click(function(){
			if(opt.page>1){
				opt.page--;
				loadPage(htmlObj, opt);
				loadMedia(htmlObj, opt.data[opt.page-1]);
			}
		});
		
		loadPage(htmlObj, opt);
		
		$("body").append(htmlObj);
	}
	
	
	var options = {
		data:{},
		page:1
	};
	var data = {url:'',type:''};
	$.extend({
		showMedia:function(opt) {
			var opt2 = $.extend({}, options, opt||{});
	    	return showMedia(opt2);
	    }
	});
})(jQuery);